package com.example.demo.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.woniuxy.movice.entity.Cinema;
import com.woniuxy.movice.entity.MainTheater;
public interface CinemaMapper {
	//查询所有分影院的详细信息
	@Select("SELECT yid,yname,yaddress,m.zid FROM cinema c INNER JOIN main_theater m WHERE c.zid=m.zid ")
	@Results({
		@Result(column ="zid",property = "zid"),
		@Result(column="zid",property="mainTheater",one=@One(
				select="findMainTheater"
				))
	})
	public List<Cinema> findAllCinemas();
	@Select("select zname from main_theater where zid=#{zid}")
	public MainTheater findMainTheater(Integer zid);
	//根据分影院id查询影院详情
	@Select("SELECT *FROM cinema c INNER JOIN main_theater m WHERE c.zid=m.zid AND id=#{id}")
	@Results({
		@Result(column ="zid",property = "zid"),
		@Result(column="zid",property="mainTheater",one=@One(
				select="findMainTheater"
				))
	})
	public Cinema findIdByCinema(Integer id);
	//根据id删除分影院
	@Delete("DELETE FROM cinema WHERE id=#{id}")
	public void deleteIdByCinema(Integer id);
	//添加分影院
	@Insert("INSERT INTO cinema (yname,yphone,yaddress,ytext,yimg) VALUES (#{yname},#{yphone},#{yaddress},#{ytext},#{yimg})")
	public void addCinema(Cinema cinema);
	//根据管理员登录账号查询所在总影院的id
	@Select("SELECT zid FROM main_theater WHERE acount=#{acount}")
	public int findByZid(Integer acount);
	//修改分影院信息
	@Update("UPDATE cinema SET yname=#{yname},yphone=#{yphone},yaddress=#{yaddress},ytext=#{ytext},yimg=#{yimg} WHERE yid=#{yid}")
	public void updateCinema(Integer yid);
	
}
